import store from '../index.js';
import http from '@/common/http.js'
import $api from 'api'

const state = {
	userInfo: uni.getStorageSync('userInfo') || '',
	yingdi:[],
	menpiao:[]
}

const mutations = {
	// 更新用户信息
	UPDATE_USERINFO: function(state, payLoad) {
		state.userInfo = payLoad.data
		uni.setStorageSync('userInfo', payLoad.data);
		uni.setStorageSync('token', payLoad.data.token);
	},
	// 修改购物车
	EDIT_YINGDI: function(state, payLoad) {
		state.yingdi = payLoad
		console.log('修改购物车',state.yingdi)
	},
}

const actions = {
	// 获取用户信息
	async getUserInfo(context) {
		console.log(context)
		let userInfo = await $api.getUserInfo()
		context.commit('UPDATE_USERINFO', userInfo)
	}
}

export default {
	state,
	mutations,
	actions
}
